

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: false,
		title: null,
		nocBeerTicketMember: {},
        method: '1',
        number: '',
        errnum: '',
        result:{
            id: null,
            type:null
        },
        intime: null,
        outtime: null,
        TotalMember: null,
        TotalCount: null,
        message: null,
        isSign: null
	},
    mounted() {
        this.$refs.number.focus();
    },
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.nocBeerTicketMember = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
		        //var memberId = vm.result.id;
                var url = vm.method == 1 ? "noc/nocbeerticketmember/in" : "noc/nocbeerticketmember/out";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    dataType: "json",
                    data: {id:vm.result.id,type:vm.result.type},
                    success: function(r){
                        if(r.code === 0) {
                            vm.number = "";
                            //layer.msg("操作成功", {icon: 1});
                            vm.TotalMember = r.TotalMember;
                            vm.TotalCount = r.TotalCount;
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }else {
                            //layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "noc/nocbeerticketmember/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(id){
			$.get(baseURL + "noc/nocbeerticketmember/info/"+id, function(r){
                vm.nocBeerTicketMember = r.nocBeerTicketMember;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
        select: function (event) {
		    console.log(vm.number);
            var memberId = vm.number;
            $.ajax({
                type: "POST",
                url: baseURL + "noc/nocmember/getMemberId",
                contentType: "application/json",
                data: memberId,
                success: function(r){

                    if(r.code == 0){

                        if(r.result==null){
                            vm.errnum = memberId+"二维码未查询到";
                            vm.message = false;
                            vm.result = {};
                            vm.number = '';
                        }else{
                            vm.errnum = "可以通过";
                            vm.message = true;
                            vm.result.id = r.result.id;
                            vm.result.type = r.result.type;
                            //调用签到逻辑
                            vm.saveOrUpdate();
                        }
                        if(r.result.isSign==1&&vm.method==1){
                            layer.msg("此码已在"+r.result.signTime+"进场", {icon: 1});
                        }
                    }else{
                        vm.message = false;
                        vm.result = {};

                        vm.errnum = memberId+""+ r.msg;
                        vm.number = '';
                    }

                }
            });
        },
        getfocus: function (event) {
            var el = event.currentTarget;
            el.focus();
        }
	}
});